package aex.service;



import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import aex.dao.TherapyDao;
import aex.domain.Medicines;
import aex.domain.Therapy;
import aex.util.PageBean;



@Transactional(readOnly = false)
@Service(TherapyService.SERVICE_NAME)

public class TherapyService  {

	
	public static final String SERVICE_NAME="aex.service.TherapyService";
	/**
	 * 以注解的形式让spring为我们注入dao的实现类
	 */
	@Resource(name = TherapyDao.SERVICE_NAME)
	public TherapyDao dao;
	
	public TherapyService() {
		
	}
	public Therapy findByID(Serializable id) {
		return dao.findObjectByID(Integer.parseInt(id+""));
	}
	public void deleteById(Serializable id) {
		dao.deleteObjectByIDs(Integer.parseInt(id+""));
	}
	public void save(Therapy obj) {
		dao.save(obj);
	}
	public void update(Therapy obj) {
		dao.merge(obj);
	}
	public PageBean<Therapy> findAllByCategory(PageBean<Therapy> pageBean,
			String id) {
		LinkedHashMap<String, String> orderby=new LinkedHashMap<String, String>();
		orderby.put("tName.thOrderBy", "asc");
		return dao.findPageBean("and tName.articleCategory = "+id , null, orderby, pageBean);
	}
	public int findTherapyCount() {
		LinkedHashMap<String, String> orderby=new LinkedHashMap<String, String>();
		orderby.put("tName.thOrderBy", "asc");
		return dao.findCollectionByConditionNoPage(" ", null, orderby).size();
	}
	public List<Therapy> findAllByCategoryNoPage(String id) {
		LinkedHashMap<String, String> orderby=new LinkedHashMap<String, String>();
		orderby.put("tName.thOrderBy", "asc");
		return dao.findCollectionByConditionNoPage("and tName.articleCategory = "+id, null, orderby);
	}
	public List<Therapy> findByKeyWord(String keyWord) {
		LinkedHashMap<String, String> orderby=new LinkedHashMap<String, String>();
		orderby.put("tName.thOrderBy", "asc");
		return dao.findCollectionByConditionNoPage("and tName.thName like '%"+keyWord+"%' ", null, orderby);
	}
}
